package com.ruiyian.bridge.project.controller;

import com.ruiyian.bridge.project.domain.DeviceWarnSet;
import com.ruiyian.bridge.project.service.DeviceWarnSetService;
import com.ruiyian.common.annotation.Log;
import com.ruiyian.common.core.controller.BaseController;
import com.ruiyian.common.core.domain.AjaxResult;
import com.ruiyian.common.core.page.TableDataInfo;
import com.ruiyian.common.enums.BusinessType;
import com.ruiyian.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 设备报警
 *
 * @author ruiyian
 * @date 2022-01-19
 */
@RestController
@RequestMapping("/bridge/project/warn")
public class DeviceWarnSetController extends BaseController
{
    @Autowired
    private DeviceWarnSetService tDeviceWarnSetService;

    /**
     * 查询超限预警设置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DeviceWarnSet deviceWarnSet)
    {
        startPage();
        List<DeviceWarnSet> list = tDeviceWarnSetService.selectTSensorWarnSetList(deviceWarnSet);
        return getDataTable(list);
    }

    /**
     * 导出超限预警设置列表
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:warn:export')")
    @Log(title = "超限预警设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceWarnSet deviceWarnSet)
    {
        List<DeviceWarnSet> list = tDeviceWarnSetService.selectTSensorWarnSetList(deviceWarnSet);
        ExcelUtil<DeviceWarnSet> util = new ExcelUtil<DeviceWarnSet>(DeviceWarnSet.class);
        try {
            util.exportExcel(response, list, "超限预警设置数据");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取超限预警设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:warn:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tDeviceWarnSetService.selectTSensorWarnSetById(id));
    }

    /**
     * 新增超限预警设置
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:warn:add')")
    @Log(title = "超限预警设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceWarnSet deviceWarnSet)
    {
        return toAjax(tDeviceWarnSetService.insertTSensorWarnSet(deviceWarnSet));
    }

    /**
     * 修改超限预警设置
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:warn:edit')")
    @Log(title = "超限预警设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceWarnSet deviceWarnSet)
    {
        return toAjax(tDeviceWarnSetService.updateTSensorWarnSet(deviceWarnSet));
    }

    /**
     * 删除超限预警设置
     */
    @PreAuthorize("@ss.hasPermi('bridge:project:warn:remove')")
    @Log(title = "超限预警设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tDeviceWarnSetService.deleteTSensorWarnSetByIds(ids));
    }
}
